//
//  ViewController.swift
//  WeatherDemo
//
//  Created by 张峰 on 15/3/4.
//  Copyright (c) 2015年 wdlgame. All rights reserved.
//

import Alamofire
import UIKit


class CityListCell: UITableViewCell {
    
    @IBOutlet weak var cnNameLabel: UILabel!
    @IBOutlet weak var enNameLabel: UILabel!
    
}

class CityListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var tableView: UITableView!
    

    var cityList:[(cn:String,en:String)] = [
        
        ("北京","BEIJING"),
        ("上海","SHANGHAI"),
        ("海口","HAIKOU"),
        ("广州","GUANGZHOU"),
        ("郑州","ZEHNGZHOU"),
        ("太原","TAIYUAN"),
        ("晋城","JINCHENG"),
        ("天津","TIANJIN"),
        ("西安","XIAN"),
        ("成都","CHENGDU"),
        ]
    
    var colorList:[String] = [
        
        "#239631",
        "#4fb47e",
        "#63bac8",
        "#366784",
        "#cac336",
        "#3aa487",
        "#7cc1b1",
        
        ]

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "城市列表"
        self.tableView.delegate = self
        self.tableView.dataSource = self
        
        self.view.addSubview(tableView)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: TableViewDataSouce Method
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cityList.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier") as CityListCell
        
        let city = cityList[indexPath.row]
        cell.cnNameLabel.text = city.cn
        cell.enNameLabel.text = city.en

        cell.cnNameLabel.textColor = UIColor.whiteColor()
        cell.enNameLabel.textColor = UIColor.whiteColor()
        
        cell.selectionStyle = .None
        
        var colorStr = colorList[indexPath.row%7]
        cell.contentView.backgroundColor = UIColor(hexString: colorStr)

        return cell
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        var weatherViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("WeatherViewController") as WeatherViewController
        weatherViewController.cityName = cityList[indexPath.row]
        weatherViewController.bgColor = UIColor(hexString:colorList[indexPath.row%7])

        self.navigationController?.pushViewController(weatherViewController, animated: true)
        
    }
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 80
    }
    
}

